import java.util.concurrent.locks.ReentrantLock;

public class MyTask implements Runnable {
    private String name;
    private ReentrantLock locker;

    public MyTask(String name, ReentrantLock locker) {
        this.name = name;
        this.locker = locker;
    }
    @Override
    public void run(){
        locker.lock();
        try{
            System.out.println(this.name + "--运行在线程"+ Thread.currentThread().getId());
        }finally {
            locker.unlock();
        }
    }
}
